package com.ruoyi.equip.util;

import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.equip.domain.ThingModel;
import com.ruoyi.equip.domain.cache.DeviceTagCache;
import com.ruoyi.td.vo.ThingModelVo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class ModelCacheUtils {



    public static HashMap<String,Map<String, ThingModelVo.Property> > stringMapHashMap=new HashMap<>();
    /**
     * 设置cache key
     *
     * @param configKey 参数键
     * @return 缓存键key
     */
    public static String getCacheKey(String configKey) {
        return CacheConstants.THING_MODEL_KEY + configKey;
    }


    public static Map<String, ThingModelVo.Property> getModelCache(String key) {
        return  stringMapHashMap.get(getCacheKey(key));
    }

    /**
     * 设置物模型缓存
     *
     * @param key        参数键
     * @param properties 物模型数据
     */
    public static void setThingModelCache(String key, List<ThingModelVo.Property> properties) {
        if (properties == null) {
            removeThingModelCache(key);
        } else {
            Map<String, ThingModelVo.Property> modelMaps = new HashMap<>();
            properties.forEach(property -> {
                modelMaps.put(property.getIdentifier(), property);
            });
            stringMapHashMap.put(getCacheKey(key),modelMaps);
        }
    }

    /**
     * 移除物模型缓存
     *
     * @param key
     */
    public static void removeThingModelCache(String key) {
        stringMapHashMap.remove(getCacheKey(key));
    }
}
